const mongoose = require('mongoose')
const Schema = mongoose.Schema;

const UserSchema = new Schema({
    username: {
        type: String,
        required: true,
    },
    password: {
        type: String,
        required: true
    },
    mobile: {
        type: String,
        required: true,
        unique: true
    }
}, {
   timestamps: {createdAt: 'created', updatedAt: 'updated'} 
})

UserSchema.methods.findMobile = function(mobile, callback) {
    return this.model('User').findOne({mobile}, callback)
}

UserSchema.methods.findMobilePas = function (mobile, password, callback) {
    return this.model('User').findOne({ mobile, password }, callback)
}


module.exports = mongoose.model('User', UserSchema)